﻿document.write('<script type="text/javascript"src="http://webapi.amap.com/maps?v=1.2&key=ab5ae8097e26040fa604012b73e78f03"></script> ')
document.write('<script type="text/javascript" src="jquery-1.8.2.min.js"></script> ')
document.write('<script type="text/javascript">')
    var ln;
var point;
var mapObj;
var zom;
var toolBar, locationInfo;
var myBoolean = false;
var tool;
function raa() {

    // x=   WebService.HelloWorld();
    //  alert("adda");
    //  x = ln.getLng();
    //  var y = ln.getlnt();
    alert(x);

}
function x() {
    //  $("#fm").attr("src", "dituxianshi.aspx");

    toolBar.doLocation()
    //  myBoolean = true;
}
function a() {
    //  weba.wajax.HelloWorld(onresult);
    x = ln.getLng();
    y = ln.getLat();
    weba.wajax.xiougai(x, y, '<%= Request.QueryString["id"] %>', onresult)

}
function onresult(result) {
    alert(result);
}
function xh(rx, ry, d, nm, sm, ig) {
    var marker = new AMap.Marker({
        id: d,
        draggable: true,
        position: new AMap.LngLat(rx, ry),
        icon: "http://webapi.amap.com/static/images/marker_sprite.png",
        offset: { x: -8, y: -34 }
    });// 创建点坐标
    mapObj.addOverlays(marker);

    var info = [];
    info.push("<img src='Images/" + ig + "'width='30' height='30'>");
    info.push("&nbsp;&nbsp;" + sm + "<br  />");
    info.push("&nbsp;&nbsp;" + nm);

    var inforWindow = new AMap.InfoWindow({
        //offset: new AMap.Pixel(45, -34),
        offset: new AMap.Pixel(0, -23),
        content: info.join("")
    });
    AMap.event.addListener(marker, "click", function (e) {
        inforWindow.open(mapObj, marker.getPosition());
    });
    AMap.event.addListener(marker, "dragend", function (e) {
        var nx = e.lnglat.getLng();
        var ny = e.lnglat.getLat();
        if (confirm("确定要更新" + nm + "吗？")) {// alert();
            weba.wajax.genxing(nx, ny, d, onresult)
        }
    });
}
function onresult(result) {
    alert(result);
}
function suc(result) {
    var ps = new AMap.LngLat(result[0].lx, result[0].ly);
    // alert(result.length);
    mapObj.setCenter(ps);
    mapObj.setZoom(zom);

    for (var i = 0; i < result.length; i++) {
        xh(result[i].lx, result[i].ly, result[i].Id, result[i].name, result[i].shuoming, result[i].tupianurl);
        //var marker = new AMap.Marker({
        //    id: result.Id,
        //    position: new AMap.LngLat(result[i].lx, result[i].ly),
        //    icon: "http://webapi.amap.com/static/images/marker_sprite.png",
        //    offset: { x: -8, y: -34 }
        //});// 创建点坐标
        //mapObj.addOverlays(marker);

        //var info = [];
        //info.push("<b>&nbsp;&nbsp;" + result[i].name + "</b>");
        //info.push("&nbsp;&nbsp;" + result[i].shuoming);
        //info.push("&nbsp;&nbsp;" + result[i].Id);

        //var inforWindow = new AMap.InfoWindow({
        //    offset: new AMap.Pixel(45, -34),
        //    content: info.join("<br  />")
        //});
        //AMap.event.addListener(marker, "click", function (e) {
        //    inforWindow.open(mapObj, marker.getPosition());
        //});
    }

    //if (myBoolean == true)
    //{
    //    //  toolBar.doLocation()
    //    alert("a");
    //}
}
function initialize() {
    pd = '<%= Request.QueryString["pid"] %>'
    zom = '<%= Request.QueryString["zm"] %>'
    mapObj = new AMap.Map("container"); // 创建地图实例
    if (pd == "") {
        point = new AMap.LngLat(121.550331, 29.868038); // 创建点坐标
        mapObj.setCenter(point);
    }
    else {
        weba.wajax.getbyid(pd, suc);
        point = new AMap.LngLat(121.550331, 29.868038);
        //point = new AMap.LngLat(jd, wd);
        //var markera = new AMap.Marker({
        //    id: "m122",
        //    position: new AMap.LngLat(jd, wd),
        //    icon: "http://webapi.amap.com/static/images/marker_sprite.png",
        //    offset: { x: -8, y: -34 }
        //});// 创建点坐标
        //mapObj.addOverlays(markera);
    }

    //  alert(ln.getLng());
    mapObj.plugin(["AMap.ToolBar", "AMap.OverView,AMap.Scale"], function () {
        // 加载工具条
        tool = new AMap.ToolBar({
            direction: false, // 隐藏方向导航
            ruler: false, // 隐藏视野级别控制尺
            autoPosition: false // 禁止自动定位
        });
        mapObj.addControl(tool);

        // 加载鹰眼
        view = new AMap.OverView();
        mapObj.addControl(view);

        // 加载比例尺
        scale = new AMap.Scale();
        mapObj.addControl(scale);
    });
    // var point = new AMap.LngLat(116.404, 39.915); // 创建点坐标
    // 设置地图中心点坐标
    mapObj.plugin(["AMap.ToolBar"], function () {
        toolBar = new AMap.ToolBar(); //设置地位标记为自定义标记  
        mapObj.addControl(toolBar);
        AMap.event.addListener(toolBar, 'location', function callback(e) {
            locationInfo = e.lnglat;
        });
    });

    mapObj.bind(mapObj, "click", function (e) {
        ln = e.lnglat;
        var markera = new AMap.Marker({
            id: "m123",
            position: e.lnglat,
            icon: "http://webapi.amap.com/static/images/marker_sprite.png",
            offset: { x: -8, y: -34 }
        });
        //  alert(ln.getLng());
        mapObj.addOverlays(markera);
        mapObj.setCenter(ln);

    });
}

document.write('</script>')
   